package com.itserver.controller.sysController;

import com.itserver.pojo.PageResult;
import com.itserver.pojo.Result;
import com.itserver.pojo.sys.Menu;
import com.itserver.service.sys.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sys/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    @GetMapping
    public Result list(Menu params) {
        PageResult<Menu> menus =  menuService.list(params);
        return Result.success( menus );
    }

    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids) {
        menuService.delete(ids);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody Menu menu ) {
        menuService.update(menu);
        return Result.success();
    }

    @PostMapping
    public Result add (@RequestBody Menu menu){
        menuService.add(menu);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Menu menu = menuService.getById(id);
        return Result.success(menu);
    }

}
